package com.company;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author jrue
 * @version 1.0
 * @date 2020/3/23 19:23
 */
class MyNode {
    int x,y;
}
public class Main62 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String s1 = s.substring(1, s.length() - 1);
        String[] nodes = s1.split("],");
        ArrayList<MyNode> myNodes = new ArrayList<>();

        for (int i = 0; i < nodes.length; i++) {
            String node = nodes[i];
            if (i == nodes.length - 1) node = node.substring(1,node.length() - 1);
            else node = node.substring(1);
            String[] values = node.split(",");
            MyNode node1 = new MyNode();
            node1.x = Integer.valueOf(values[0]);
            node1.y = Integer.valueOf(values[1]);
            myNodes.add(node1);
        }

        int res = 0;
        for (int i = 0; i < myNodes.size() - 1; i++) {
            MyNode startNode = myNodes.get(i);
            for (int j = i + 1; j < myNodes.size(); j++) {
                MyNode endNode = myNodes.get(j);
                if (startNode.x == endNode.y) {
                    int p  =startNode.y;
                    res++;
                    while (p != endNode.y) {
                        for (int k = 0; k < myNodes.size(); k++) {
                            if (myNodes.get(k).x == p) {
                                p = myNodes.get(k).y;break;
                            }
                        }
                        res++;
                    }
                }
            }
        }
        if (res == 1) res = 0;
        System.out.println(res);
    }

}
